<template>
  <view class="flex-col">

    <view :class="boole?'bottom115':''">
      <!--车辆基础信息-->
      <table-info v-model="detailForm"/>

      <!--附件-->
      <attachments v-model="detailForm" :boole="boole" ref="refAttachments"/>

      <view v-if="boole === false">
        <!--退保信息（商业险信息）-->
        <cancellation-info v-model="detailForm"/>
        <!--财务审核信息反馈-->
        <finance-message v-model="detailForm"/>
      </view>

    </view>
    <!--审批流程-->
    <exam-flow v-if="flowId" :instanceId="flowId"/>

    <view class="button-container" v-if="boole">
      <button class="btn-item" @click="submit">提 交</button>
    </view>

  </view>
</template>

<script>
import {getCancellationDetails, submitCancellationDetails, getDetails} from "@/api/cancellation";
import tableInfo from './components/tableInfo.vue'
import attachments from './components/attachments.vue'
import cancellationInfo from './components/cancellationInfo.vue'
import financeMessage from './components/financeMessage.vue'

export default {
  name: 'add',
  components: {tableInfo, attachments, cancellationInfo, financeMessage},
  computed: {},
  watch: {},
  data() {
    return {
      flowId: null,
      boole: false,
      detailForm: {
        attachmentUrl: '',
        tableData: [],
      }
    };
  },
  onLoad(op) {
    let title = "";
    this.flowId = op?.flowId;
    if (op?.type === "edit") {
      let id = [op?.id]
      this.handleDetail(id);
      title = "处理退保工单";
      this.boole = true;
    }
    if (op?.type === "view") {
      this.handleGetDetails(op?.id);
      title = "退保工单信息";
      this.boole = false;
    }
    this.detailForm.carId = op?.carId;
    uni.setNavigationBarTitle({
      title,
    });
  },
  created() {
  },
  mounted() {
  },
  methods: {
    //获取处理详情
    handleDetail(id) {
      getCancellationDetails(id).then(res => {
        if (res.code === 200) {
          this.detailForm = res.data
        }
      })
    },

    async handleGetDetails(id) {
      try {
        const res = await getDetails(id)
        this.detailForm = res.data
      } catch (e) {
        console.log(e)
      }
    },

    async submit() {
      try {
        uni.showLoading();
        await this.$refs.refAttachments.handleEffect()
        let res = await submitCancellationDetails(this.detailForm)
        if (res.code === 200) {
          this.$modal.msgSuccess("提交成功");
          setTimeout(() => {
            this.$tab.navigateBack();
          }, 1000);
        }
      } catch (error) {
        if (typeof error === 'string') {
          this.$nextTick(() => {
            uni.pageScrollTo({
              selector: error,
            });
          });
        } else {
          console.error(error)
        }
      } finally {
        uni.hideLoading();
      }
    },
  },
};
</script>

<style scoped lang=""></style>


